package com.example.mardan.views;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import com.example.mardan.viewmodel.SongciViewModel;
import com.example.read.R;

public class SongciDetailActivity extends AppCompatActivity {
    private TextView tvTitle, tvType, tvContent, tvExplanation, tvAppreciation, tvAuthor;
    private SongciViewModel viewModel;





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        tvTitle = findViewById(R.id.tv_title);
        tvType = findViewById(R.id.tv_type);
        tvContent = findViewById(R.id.tv_content);
        tvExplanation = findViewById(R.id.tv_explanation);
        tvAppreciation = findViewById(R.id.tv_appreciation);
        tvAuthor = findViewById(R.id.tv_author);

        int detailId = getIntent().getIntExtra("detailid", 1);

        viewModel = new ViewModelProvider(this).get(SongciViewModel.class);
        viewModel.getDetail(detailId).observe(this, detail -> {
            if (detailId != -1 && detail != null) {
                tvTitle.setText(detail.getTitle());
                tvType.setText(detail.getType());
                tvContent.setText(detail.getContent());
                tvExplanation.setText(detail.getExplanation());
                tvAppreciation.setText(detail.getAppreciation());
                tvAuthor.setText(detail.getAuthor());
            } else {
                Log.e("SongciDetailActivity", "Detail is null or detailId is -1");
                tvTitle.setText("无法加载诗词详情");
            }
        });
    }
}